package 华为OD机试真题2023.进阶题;

import utils.MyUtil;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Scanner;

public class HJ31_统计匹配的二元组个数 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(new File("src/main/java/华为OD机试真题2023/进阶题/input/31.txt"));
        MyUtil.START();
        Solution(in);
        //        Solution2(in);
        MyUtil.END();
    }

    static void Solution(Scanner in) {
        in.nextInt(); // 前两个参数没用
        in.nextInt();
        in.nextLine(); // 吸收回车
        String[] sArrayA = in.nextLine().split(" ");
        String[] sArrayB = in.nextLine().split(" ");
        HashMap<String, Integer> hash = new HashMap<>();
        for (String strA : sArrayA) {
            hash.put(strA, hash.getOrDefault(strA, 0) + 1);
        }
        int res = 0;
        for (String strB : sArrayB) {
            res += hash.getOrDefault(strB, 0);
        }
        System.out.println(res);
    }

    static void Solution2(Scanner sc) {
        int m = Integer.valueOf(sc.nextLine());
        int n = Integer.valueOf(sc.nextLine());
        String mStr = sc.nextLine();
        String nStr = sc.nextLine();
        String[] mArr = mStr.split(" ");
        String[] nArr = nStr.split(" ");
        HashMap<String, Integer> map = new HashMap();

        int num = 0;
        for (int i = 0; i < m; i++) {

            if (map.get(mArr[i]) == null) {
                map.put(mArr[i], 1);
            } else {
                map.put(mArr[i], map.get(mArr[i]) + 1);
            }
        }

        for (int j = 0; j < n; j++) {
            Integer integer = map.get(nArr[j]);
            if (integer != null) {
                num += integer;
            }
        }
        System.out.println(num);
    }
}
